package com.csce.domain.entity.exam.vo;

import com.doudou.core.container.ListUtil;
import lombok.*;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;

/**
 * @author zzxjs
 * @since 2023/8/8
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
@Builder
@ToString
public class ExStatus {

    /**
     * 做对的数量
     */
    private int success = 0;
    /**
     * 最总得分
     */
    private Double score;
    /**
     * 状态列表
     */
    List<ExExamQuestion> examQuestionList = ListUtil.list(true);

    public ExStatus addExamQuestionList(ExExamQuestion examQuestion) {
        this.examQuestionList.add(examQuestion);
        if (examQuestion.getIsRight().equals(1)) {
            return addSuccess();
        }
        return examQuestion.getIsRight() == 1 ? addSuccess() : this;
    }

    public ExStatus addSuccess() {
        this.success++;
        return this;
    }

    public ExStatus calculate(Integer allCount) {
        this.score = BigDecimal.valueOf(this.success).divide(BigDecimal.valueOf(allCount), 2, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)).doubleValue();
        return this;
    }
}
